package com.geelaro.register.domain.entity;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.Table;

//部门
@Entity // 声明实体类
@Table // 配置实体类和表的映射关系
public class Department {

	@Id // 声明主键的配置
	@GeneratedValue(strategy = GenerationType.IDENTITY) // 配置主键的生成策略
	@Column // 配置属性和字段的映射关系
	private Integer id;
	private String departmentName;

	/*
	 * 使用注解的形式配置多表关系 1.声明关系 
	 * targetEntity:对方对象的字节码对象
	 * 2.配置外键（中间表）
	 *			@JoinColumn
	 *			name外键字段名称
	 *			referencedColumnName参照主表的主键字段名称
	 *在一的一方添加了
	 *
	 */
	// 配置部门员工一对多关系
	//@OneToMany(targetEntity = Employee.class)
	//@JoinColumn(name = "department_id",referencedColumnName = "id")
	
	//放弃外键配置   mappedBy：对方配置关系的属性名称
	@OneToMany(mappedBy = "department")
	private Set<Employee> employees = new HashSet<Employee>();

	public Set<Employee> getEmployees() {
		return employees;
	}

	public void setEmployees(Set<Employee> employees) {
		this.employees = employees;
	}

	public Department() {
	}

	public Department(Integer id, String departmentName) {
		this.id = id;
		this.departmentName = departmentName;
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getDepartmentName() {
		return departmentName;
	}

	public void setDepartmentName(String departmentName) {
		this.departmentName = departmentName;
	}

	@Override
	public String toString() {
		return "Department{" + "id=" + id + ", departmentName='" + departmentName + '\'' + '}';
	}
}
